package handler

import (
	"net/http"

	"mall/service/backend/common/websocket"
	"mall/service/user/api/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

// Defining the Playground handler
func websocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		r.ParseForm()
		userId := r.Form["userId"][0]
		if len(userId) == 0 {
			logx.Errorw("websocketHandler get userId err")
			return
		}

		websocket.ServeWs(svcCtx.Hub, w, r, userId)
	}
}
